package com.example.shopping.dao;

import com.example.shopping.pojo.Brand;
import com.example.shopping.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/
//品牌
@Repository
public interface IBrandDao {
    //全部查询品牌信息
    @Select("select * from brand ")
    List<Brand> selectListBrand();

    //新增品牌信息
    @Insert("insert into brand(name,jping) values(#{name},#{jping})")
    int insertBrand(Brand brand);

    //修改品牌信息
    @Update("update brand set name=#{name},jping=#{jping} where id=#{id}")
    int updateBrand(Brand brand);

    //删除品牌信息
    @Delete("delete from brand where id =#{id}")
    int deleteIdBrand(int id);

    //查询单个
    @Select("select * from brand where id=#{id}")
    Brand selectByOne(int id);

    //模糊查询
    @SelectProvider(type = queryByLikeBrand.class, method = "queryByLike")
    List<Brand> queryLikeBrand(Brand brand);

    class queryByLikeBrand {
        public String queryByLike(Brand brand) {
            String sql = "select * from brand where 1=1  ";
            if (brand.getName() != null && !(brand.getName().equals(""))) {
                sql += "and name like  #{name} ";
            }
            if (brand.getJping() != null && !(brand.getJping().equals(""))) {
                sql += "and jping like #{jping}";
            }
            return sql;
        }
    }


}
